package com.kelvem.saas.workbanch.fsm.container;

import com.kelvem.saas.workbanch.fsm.handle.Handle;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * HandleContainer
 */
@Service
public class HandleContainer {
    
    private Map<String, Handle> map = new HashMap<>();
    
    public Handle getHandle(Class<? extends Handle> handleClazz) {
        
        String key = this.convertKey(handleClazz);
        return map.get(key);
    }
    
    public void addHandle(Handle handle) {
        String key = this.convertKey(handle.getClass());
        map.put(key, handle);
    }
    
    private String convertKey(Class<? extends Handle> handleClazz) {
        String key = handleClazz.getSimpleName();
        key = key.split("\\$\\$")[0];
        key = key.toLowerCase();
        return key;
    }
    
}
